#include <iostream>

// padding function
void pad(int padding, float *input, float *output, int new_m, int new_n, int channel, int n) {
    if (padding <= 0){
        std::cout << "padding must be greater than 0!" << std::endl;
    }else {
        int wh = new_m*new_n;
        int idx = 0;
        for (int k = 0; k < channel; k++) {
            int off_z = k * wh;
            for (int i = 0; i < new_m; i++) {
                for (int j = 0; j < new_n; j++) {
                if((i >= padding) && (i < new_m - padding) && (j >= padding) && (j < new_n - padding)) {
                    output[off_z + i*new_n + j] = input[idx];
                    idx++;
                    }else{
                    output[off_z + i*new_n + j] = 0;
                    }
                }
            }
        }
    }
}

int main() {
    int m = 2;
    int n = 2;
    int c = 2;
    int padding = 1;
    int new_m = m + 2 * padding;
    int new_n = n + 2 * padding;
    float input[2 * 2 * 2] = {1, 2, 3, 4, 5, 6, 7, 8};
    float output[new_m * new_n * 2] = {0};
    pad(padding, input, output, new_m, new_n, c, n);
    for (int i = 0; i < new_m * 2; i++) {
        for (int j = 0; j < new_n; j++) {
            std::cout << output[i * new_n + j] << " ";
        }
        std::cout << std::endl;
    }
}